package com.ruoyi.demo.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.ruoyi.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.demo.mapper.DemoFormMapper;
import com.ruoyi.demo.domain.DemoForm;
import com.ruoyi.demo.service.IDemoFormService;

/**
 * 动态表单Service业务层处理
 * 
 * @author wym
 * @date 2024-02-28
 */
@Service
public class DemoFormServiceImpl implements IDemoFormService 
{
    @Autowired
    private DemoFormMapper demoFormMapper;

    /**
     * 查询动态表单
     * 
     * @param id 动态表单主键
     * @return 动态表单
     */
    @Override
    public DemoForm selectDemoFormById(Long id)
    {
        return demoFormMapper.selectById(id);
    }

    /**
     * 查询动态表单列表
     * 
     * @param demoForm 动态表单
     * @return 动态表单
     */
    @Override
    public List<DemoForm> selectDemoFormList(DemoForm demoForm)
    {
        Map<String, Object> params = demoForm.getParams();
        LambdaQueryWrapper<DemoForm> query = new LambdaQueryWrapper<>();

                    query.like(demoForm.getFormName() != null, DemoForm::getFormName, demoForm.getFormName());



        return demoFormMapper.selectList(query);
    }

    /**
     * 新增动态表单
     * 
     * @param demoForm 动态表单
     * @return 结果
     */
    @Override
    public int insertDemoForm(DemoForm demoForm)
    {
        demoForm.setCreateTime(DateUtils.getNowDate());
        demoForm.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        return demoFormMapper.insert(demoForm);
    }

    /**
     * 修改动态表单
     * 
     * @param demoForm 动态表单
     * @return 结果
     */
    @Override
    public int updateDemoForm(DemoForm demoForm)
    {
        demoForm.setUpdateTime(DateUtils.getNowDate());
        demoForm.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
        return demoFormMapper.updateById(demoForm);
    }

    /**
     * 批量删除动态表单
     * 
     * @param ids 需要删除的动态表单主键
     * @return 结果
     */
    @Override
    public int deleteDemoFormByIds(Long[] ids)
    {

        return demoFormMapper.deleteBatchIds(Arrays.asList(ids));
    }
    /**
     * 删除动态表单信息
     * 
     * @param id 动态表单主键
     * @return 结果
     */
    @Override
    public int deleteDemoFormById(Long id)
    {

        return demoFormMapper.deleteById(id);
    }
}
